<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
use app\common\controller\Api;
use app\common\model\Area;
use app\common\model\Version;
use fast\Random;
use think\Config;
class Horseman extends Controller{
    /****
     Class register 		商家认证
     *@$post['card_image1']		身份证正面
     *@$post['card_image2']	身份证反面
     *@$post['card_image3']	手持身份证
     *@$post['charter']		营业执照
     *@$post['coba']		门头照
    */
    public function horseman(){
       $post = input('post.');
       $pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	   $word_length=11;
  	   $code = '';
       for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < $word_length; $i++){
       		$code .= $pool[mt_rand(0, $mt_rand_max)];
       }
        $data = [
        	'userid'				=>$post['user_id'],
        	'card_image1'	   		=>$post['card_image1'],
        	'card_image2'	   		=>$post['card_image2'],
        	'card_image3'	   		=>$post['card_image3'],
			'card_number'    		=>$post['card_number'],
			'truename'       		=>$post['truename'],
        	'phone'				    =>$post['phone'],
			'type'           		=>$post['type'],
        	'apply_reply'	   		=>$post['apply_reply'],
			'school_id'				=>$post['school_id'],
        	'username'			 	=>$code,
        	'status'				=>0,
        	'apply_status'	 		=>0,
        	'createtime'		 	=>time()
        ];
        $courier=Db::name('courier')->insert($data);
        if($courier){
       		$arr = [
		       'state'     => 1,
		       'message'   => "请求成功！"
	       	];
       }else{
       		$arr = [
		       'state'     => 0,
		       'message'   => "请求错误！"
	       	];
       }
       return json($arr); 
    }
    public function uploading(){
        return action('index/common/upload');
    } 
	public function condition(){
        $user_id = input('user_id');
		$courier = Db::name('courier')->where(['userid'=>$user_id])->find();
		if($courier){
			$arr = [
		       'state'     => 1,
			   'courier'   =>$courier,
	       	];
		}else{
			$arr = [
		       'state'     => 1,
			   'courier'   =>'',
	       	];
		}
		return json($arr); 
    }
	/**骑手重新认证**/     
	public function again(){
		$user_id = input('user_id');
		$courier = Db::name('courier')->where(['userid'=>$user_id])->find();
		if($courier){
			$courier_delete = Db::name('courier')->where(['userid'=>$user_id])->delete();
			if($courier_delete){
				$arr = [
					'state'       => 1,
				];
			}else{
				$arr = [
					'state'       => 0,
				];
			}
			
		}
	}
   


}